package com.xingzuo.library_home.ui;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.xingzuo.base.app.AppActivityKey;
import com.xingzuo.base.ui.mvp.base.ui.BaseActivity;
import com.xingzuo.common.view.NoSlidingViewPager;
import com.xingzuo.library_home.R;
import com.xingzuo.library_home.R2;
import com.xingzuo.library_home.adapter.MyViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
@Route(path = AppActivityKey.HOMEACTIVITY)
public class HomeActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {
    @BindView(R2.id.vp_home)
    NoSlidingViewPager vpHome;
    @BindView(R2.id.rg_home)
    RadioGroup rgHome;
    private List<Fragment> fragments=new ArrayList<>();
    private MyViewPagerAdapter adapter;
    @Override
    public int getView() {
        return R.layout.activity_home;
    }

    @Override
    public void initView() {
        vpHome.setOffscreenPageLimit(5);
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {
        Fragment asfragment= (Fragment) ARouter.getInstance().build(AppActivityKey.ASTROLABEFRAGMENT).navigation(this);
        Fragment translationFragment= (Fragment) ARouter.getInstance().build(AppActivityKey.TRANSLATIONFRAGMENT).navigation(this);
        Fragment userFragment= (Fragment) ARouter.getInstance().build(AppActivityKey.USERFRAGMENT).navigation(this);
        Fragment fileFragment= (Fragment) ARouter.getInstance().build(AppActivityKey.FILEFRAGMENT).navigation(this);
        Fragment expertFragment= (Fragment) ARouter.getInstance().build(AppActivityKey.EXPERTFRAGMENT).navigation(this);
        fragments.add(asfragment);
        fragments.add(translationFragment);
        fragments.add(userFragment);
        fragments.add(fileFragment);
        fragments.add(expertFragment);
        adapter=new MyViewPagerAdapter(getSupportFragmentManager(),fragments);
        vpHome.setAdapter(adapter);
        vpHome.setCurrentItem(0);
        rgHome.setOnCheckedChangeListener(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
    int currentFragment=0;
    @Override
    public void onCheckedChanged(RadioGroup group, int id) {

        if (id == R.id.rb_as) {
            currentFragment = 0;
        } else if (id == R.id.rb_translation) {
            currentFragment = 1;
        } else if (id == R.id.rb_user) {
            currentFragment = 2;
        } else if (id == R.id.rb_file) {
            currentFragment = 3;
        } else if (id == R.id.rb_exper) {
            currentFragment = 4;
        }
        vpHome.setCurrentItem(currentFragment);
    }
}